home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / fp-hpux.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-05  |  2.8 KB  |  113 lines

  1. /* ieee-utils/fp-hpux.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #define _INCLUDE_HPUX_SOURCE
  21.  
  22. #include <math.h>
  23. #include <stdio.h>
  24. #include <gsl/gsl_ieee_utils.h>
  25. #include <gsl/gsl_errno.h>
  26.  
  27. int
  28. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  29. {
  30.   fp_except mode = 0 ;
  31.   fp_rnd    rnd  = 0 ;
  32.  
  33.   switch (precision)
  34.     {
  35.     case GSL_IEEE_SINGLE_PRECISION:
  36.       GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  37.          GSL_EUNSUP) ;
  38.       break ;
  39.     case GSL_IEEE_DOUBLE_PRECISION:
  40.       GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  41.          GSL_EUNSUP) ;
  42.       break ;
  43.     case GSL_IEEE_EXTENDED_PRECISION:
  44.       GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  45.          GSL_EUNSUP) ;
  46.       break ;
  47.     }
  48.  
  49.  
  50.   switch (rounding)
  51.     {
  52.     case GSL_IEEE_ROUND_TO_NEAREST:
  53.       rnd = FP_RN ;
  54.       fpsetround (rnd) ;
  55.       break ;
  56.     case GSL_IEEE_ROUND_DOWN:
  57.       rnd = FP_RM ;
  58.       fpsetround (rnd) ;
  59.       break ;
  60.     case GSL_IEEE_ROUND_UP:
  61.       rnd = FP_RP ;
  62.       fpsetround (rnd) ;
  63.       break ;
  64.     case GSL_IEEE_ROUND_TO_ZERO:
  65.       rnd = FP_RZ ;
  66.       fpsetround (rnd) ;
  67.       break ;
  68.     default:
  69.       rnd = FP_RN ;
  70.       fpsetround (rnd) ;
  71.     }
  72.  
  73.   /* Turn on all the exceptions apart from 'inexact' */
  74.  
  75.   mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL ;
  76.  
  77.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  78.     mode &= ~ FP_X_INV ;
  79.  
  80.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  81.     {
  82.       /* do nothing */
  83.     }
  84.   else
  85.     {
  86.       GSL_ERROR ("HP-UX does not support the denormalized operand exception. "
  87.          "Use 'mask-denormalized' to work around this.",
  88.          GSL_EUNSUP) ;
  89.     }
  90.  
  91.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  92.     mode &= ~ FP_X_DZ ;
  93.  
  94.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  95.     mode &= ~ FP_X_OFL ;
  96.  
  97.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  98.     mode &=  ~ FP_X_UFL ;
  99.  
  100.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  101.     {
  102.       mode |= FP_X_IMP ;
  103.     }
  104.   else
  105.     {
  106.       mode &= ~ FP_X_IMP ;
  107.     }
  108.  
  109.   fpsetmask (mode) ;
  110.  
  111.   return GSL_SUCCESS ;
  112. }
  113.